﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.DrawingML.Font
{
    public class Font : XmlSerializable
    {
        [Optional]
        [XmlAttribute("typeface", Form = XmlSchemaForm.Qualified)]
        public string Typeface { get; set; }

        /// <summary>
        /// Hexadecimal number. Length: 10
        /// </summary>
        [Optional]
        [XmlAttribute("panose", Form = XmlSchemaForm.Qualified)]
        public string Panose
        {
            get { return color; }
            set
            {
                if (value == null || (value.Length == 10 && !Helpers.ParseHexadecimalValue(value)))
                {
                    throw new ArgumentException("String: " + value +
                        "is not a valid hexadecimal string or length is not 10!");
                }

                color = value;
            }
        }

        [XmlIgnore]
        private string color;

        [Optional]
        [XmlAttribute("pitchFamily", Form = XmlSchemaForm.Qualified)]
        public Nullable<byte> PitchFamily { get; set; }

        [Optional]
        [XmlAttribute("charset", Form = XmlSchemaForm.Qualified)]
        public Nullable<byte> Charset { get; set; }

        public Font() { }
    }
}
